import React,{useEffect, useState} from 'react'
import Taro from '@tarojs/taro'
import { View } from '@tarojs/components'
import './middleware.scss'

export default function middleware() {
  const [contentTxt, setcontentTxt] = useState()
  useEffect(()=>{
    const {router} = Taro.getCurrentInstance()
    Taro.$get(`/order/apps/${router.params.appid}`).then(res=>{
      if(res.code == '1') setcontentTxt(`点击以下按钮打开"${res.content}"`)
    })
  },[])
  return (
    <View className="middleware">
      <View>{{contentTxt}}</View>
      <View className="button" onClick={()=>{
        if(Taro.getCurrentInstance().router.params.appid){
          uni.navigateToMiniProgram({
            appId:Taro.getCurrentInstance().router.params.appid,
            path:Taro.getCurrentInstance().router.params.path
          })
          return;
        }
        Taro.$toast('缺少主要参数')
      }}>打开小程序</View>
    </View>
  )
}
